package com.liangge.essaysite.util;

import java.util.List;

public class Pagination<T> implements java.io.Serializable {
	// 结果集
	private List<T> resultList;
	// 结果总数
	private int totalCount;
	// 当前页码
	private int currentPage;
	// 页面结果集大小
	private int pageSize = CfgUtils.getCommonCfg().getInt(AgentKeys.P_INDEX_PAGE_SIZE);;

	public Pagination(int pageNo) {
		if (pageNo <= 0) {
			currentPage = 1;
		} else {
			currentPage = pageNo;
		}
	}

	public Pagination(int pageNo, int pageSize) {
		if (pageNo <= 0) {
			currentPage = 1;
		} else {
			currentPage = pageNo;
		}
		if (pageSize > 0) {
			this.pageSize = pageSize;
		}
	}

	// 获取当前页面结果集
	public List<T> getResultList() {
		return resultList;
	}

	// 获取结果总数
	public int getTotalCount() {
		return totalCount;
	}

	// 获取当前页码
	public int getCurrentPage() {
		return currentPage;
	}

	// 获取页面大小结果集大小
	public int getPageSize() {
		return pageSize;
	}

	// 获取分页起始位
	public int getDataStart() {
		return (currentPage - 1) * pageSize;
	}

	public int getTotalPage() {
		if(totalCount % pageSize == 0){
			return totalCount / pageSize;
		}
		return totalCount / pageSize + 1;
	}

	public void setResultList(List<T> resultList) {
		this.resultList = resultList;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
}
